/**
 * Created by zhoue on 2018/12/27.
 */
var getEchartsOption = (function () {
    var pieAreaOption = function (option) {
        if(option && Object.prototype.toString.call(option) == "[object Object]"){
        }else {
            option = {
                data: [
                    {value: 23, name: '基础设施'},
                    {value: 30, name: '房建'},
                    {value: 74, name: '海外'},
                    {value: 60, name: '其他'}
                ],
            }
        }
        return {
            title: {},
            tooltip : {
                trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series : [
                {
                    name:'业务板块',
                    type:'pie',
                    radius : '70%',
                    center: ['50%', '50%'],
                    data: option.data.sort(function (a, b) { return a.value - b.value; }),
                    roseType: 'radius',
                    label: {
                        normal: {
                            textStyle: {
                                color: 'rgba(255, 255, 255, 0.3)'
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            lineStyle: {
                                color: 'rgba(255, 255, 255, 0.3)'
                            },
                            smooth: 0.2,
                            length: 1,
                            length2: 5
                        }
                    },
                }
            ]
        };
    }

    var BarOption = function (option) {
        if(option && Object.prototype.toString.call(option) == "[object Object]"){
        }else {
            option = {
                completedata: [250, 312, 611, 454, 790],
                remaindata: [520, 532, 101, 334, 210]
            }
        }
        return {
            tooltip : {},
            legend: { show:false, },    //data数组不设置，legend不展示
            //设置图形的展示大小
            grid: {
                width: '100%',
                height: 108,
                top: 5,
                left: '0',
                right: '0',
                bootom: '0',
                containLabel: true  //y轴备注文字
            },
            toolbox: { show : false, },
            xAxis : {
                type : 'value',
                splitLine: {show: false}    //去除背景栅格
            },
            yAxis : {
                show: true,
                type: 'category',
                splitLine: {show: false},
                data : ['华北', '山东','中原','中南','华南']
            },
            series : [
                {
                    name:'已完成',
                    type:'bar',
                    stack: '总量',    //设置bar叠加
                    barCategoryGap: 6,
                    data: option.completedata,
                },
                {
                    name:'未完成',
                    type:'bar',
                    stack: '总量',
                    barCategoryGap: 6,
                    data: option.remaindata,
                }
            ]
        };
    }

    var LineOption = function (option) {
        if(option && Object.prototype.toString.call(option) == "[object Object]"){
        }else {
            option = {
                data: [30, 32, 61, 44, 38, 55, 20, 26, 23, 64, 34, 42],
            }
        }
        return {
            grid: {
                width: '100%',
                height: 108,
                top: 10,
                left: '0',
                right: '0',
                bootom: '0',
                containLabel: true  //y轴备注文字
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                splitLine: {show: false},
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
            },
            yAxis: {
                type: 'value',
                splitLine: {show: false},
            },
            series: [{
                data: option.data,
                type: 'line',
                areaStyle: {
                    opacity: 0.5,
                }
            }]
        };
    }

    var echartOption = {
        getPieAreaOption: pieAreaOption,
        getBarOption: BarOption,
        getLineOption: LineOption
    }
    return echartOption;
})();